package web.req;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import common.validation.ManualValidator;
import common.validation.ValidationResult;
import domain.Recruitment;
import web.Request;
import wrapper.Recruitment4Employer;

/**
 * Created by aceyin on 15/6/24.
 */
public class RecruitmentRequest extends Request {
    @JsonUnwrapped
    private Recruitment4Employer recruitment4Employer;

    /**
     * 因为发布招聘的表单内容比较多，所以允许商家只填写一部分内容就能创建一个招聘信息。
     * 但是只有等所有的必填属性都填写完之后这个招聘才是有效的。
     *
     * @return
     */
    @Override
    public ValidationResult validate() {
        Recruitment r = this.recruitment4Employer.getRecruitment();
        ManualValidator recruitmentValidator = ManualValidator.create(r);
        ValidationResult result = recruitmentValidator
                .notBlank("typeCode")
                .notBlank("name")
                .gt("salary", 0)
                .validate();

        if (result.isFailed()) {
            return result;
        }
        return result;
    }

    public Recruitment4Employer getRecruitment4Employer() {
        return recruitment4Employer;
    }

}
